import { State } from "framework/FSM/AState";
import { Harvester } from "./Harvester";
import { BehaviorMask } from "GameLoop/WorldState/WorldConfig";
import { Porter } from "./Porter";
import { Filler } from "./Filler";
import { NullBehavior } from "./NullBehavior";
import { Manager } from "./Manager";
import { Carryer } from "./Carryer";
import { CombatBehavior  } from "./CombatBehavior";




/**
 * 行为模式
 * 采集行为
 * 升级行为
 */ 
 /*@profile*/
export class BehaviorMode<T extends IStateArg<Creep>>  extends State<T>
{
    private behaviorMap:[BehaviorMask,State<T>][] = [
        [BehaviorMask.harvest, new Harvester<T>()],
        [BehaviorMask.movefill, new Carryer<T>()],
        [BehaviorMask.porter,  new NullBehavior<T>()],
        [BehaviorMask.fill, new Filler<T>()],
        [BehaviorMask.manager, new Manager<T>()],
        [BehaviorMask.upgrade, new NullBehavior<T>()],
        [BehaviorMask.build, new NullBehavior<T>()],
    
        [BehaviorMask.repair, new NullBehavior<T>()],
        [BehaviorMask.scout, new NullBehavior<T>()],
        [BehaviorMask.claim, new NullBehavior<T>()],
        [BehaviorMask.attack,  new CombatBehavior<T>()],
        [BehaviorMask.defend,  new NullBehavior<T>()]
        ,]
 
    //
    public  getActions(arg:T):Action[]
    {
        for(let k of this.behaviorMap)
        {
            const mask = k[0];
            const msk =  arg.entity.memory.msk;
            if(mask &  msk)
            {
                const actions = k[1].getActions(arg);
                if(actions.length>0)
                {
                    return actions
                }
            }
        }
           
        return [ ];
    }
}
